import { View } from "../../../../mvc/core/View";
import { EquipTargetType } from "../../../resource/info/EquipTargetType";
import { NetDispatcher } from "../../../../mvc/core/NetDispatcher";
import { ServerCommand } from "../../../mvc/ServerCommand";
import { EqStrengthEnableBtn } from "./EqStrengthEnableBtn";
import { ObjCreate } from "../../common/ObjCreate";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { StrengthAddConfig } from "../../../resource/StrengthAddConfig";
import { PetUtil } from "../../pet/info/PetUtil";
import { PlayerEqStrengthInfo } from "./PlayerEqStrengthInfo";
import { ToolTipInfo } from "../../../model/ToolTipInfo";
import { ColorConfig } from "../../../resource/ColorConfig";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { Language } from "../../../../../extend/language/Language";
import { NormalTooltip } from "../../common/tooltip/NormalTooltip";
import { StrengthenAddInfo } from "../../../resource/info/StrengthenAddInfo";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { GModuleEvent } from "../../../mvc/GModuleEvent";
type int = number;
//class EquipmentStrengthAddPanel
    
    export  class EquipmentStrengthAddPanel extends View
    {
        constructor()
        {
            super();
            this._equipTargetType = EquipTargetType.StrengthenTarget;
            this._btnDict = new Map<any, any> /* flash.utils.Dictionary */();
            addEventListener(flash.events.Event.ADDED_TO_STAGE, this.onAddToStageHandler);
            return;
        }

        public set curCareer(arg1: int)
        {
            this._curCareer = arg1;
            return;
        }

        public set mode(arg1: string)
        {
            this._mode = arg1;
            this.init();
            this.initEnable();
            return;
        }

        public set equipTargetType(arg1: int)
        {
            this._equipTargetType = arg1;
            return;
        }

        /* internal  */onAddToStageHandler(arg1: Object /* flash.events.Event */): void
        {
            NetDispatcher.addCmdListener(ServerCommand.RolepackDataChange, this.updateEnable);
            NetDispatcher.addCmdListener(ServerCommand.RolePackItemsChange, this.updateEnable);
            addEventListener(flash.events.Event.REMOVED_FROM_STAGE, this.onRemoveFromStageHandler);
            this.updateEnable();
            return;
        }

        /* internal  */onRemoveFromStageHandler(arg1: Object /* flash.events.Event */): void
        {
            NetDispatcher.removeCmdListener(ServerCommand.RolepackDataChange, this.updateEnable);
            NetDispatcher.removeCmdListener(ServerCommand.RolePackItemsChange, this.updateEnable);
            removeEventListener(flash.events.Event.REMOVED_FROM_STAGE, this.onRemoveFromStageHandler);
            return;
        }

        /* internal  */init(): void
        {
            if (this._strengBtn == null) 
            {
                this._strengBtn = new EqStrengthEnableBtn();
                this._strengBtn.label = "";
                this._strengBtn.setSize(26, 26);
                this._strengBtn.x = 0;
                this._strengBtn.y = 0;
                this._strengBtn.styleName = "StrengthAddDisableBtn";
                this._strengBtn.name = "6";
                this._strengBtn.addEventListener(flash.events.MouseEvent.MOUSE_OVER, this.onMouseOverHandler);
                addChild(this._strengBtn);
                this._strengTxt = ObjCreate.createTextField("+6", this._strengBtn.x + 3, this._strengBtn.y + this._strengBtn.height, 40, 20, this, new GTextFormat(FontUtil.EmbedNumberName, 14, 16776960));
                this._strengTxt.embedFonts = true;
            }
            return;
        }

        /* internal  */initEnable(): void
        {
            var loc2=0;
            var loc3=0;
            var loc4=null;
            var loc5=0;
            var loc6=false;
            if (this._strengTxt == null || this._strengBtn == null) 
            {
                this.init();
            }
            this._strengTxt.text = "+" + this._lowLevel;
            this._strengBtn.name = "" + this._lowLevel;
            this._strengBtn.styleName = "StrengthAddDisableBtn";
            var loc1=this._lowLevel;
            while (loc1 <= this._maxLevel) 
            {
                loc2 = this._curCareer;
                loc3 = loc1;
                loc4 = StrengthAddConfig.instance.getStrengthenAddInfo(this._equipTargetType, loc2, loc3);
                loc5 = this.getStrengthAmount(loc3);
                if (loc4 != null) 
                {
                    if (loc6 = loc5 >= loc4.amount) 
                    {
                        this._strengBtn.styleName = "StrengthAddEnableBtn";
                        this._strengBtn.name = loc1.toString();
                        this._strengTxt.text = "+" + loc1;
                    }
                    else 
                    {
                        break;
                    }
                }
                ++loc1;
            }
            this._strengBtn.drawNow();
            return;
        }

        /* internal  */updateTooltipData(): void
        {
            if (this._strengBtn) 
            {
                this._strengBtn.toolTipData = this.getToolTipData(int(this._strengBtn.name));
            }
            return;
        }

        /* internal  */getStrengthAmount(arg1: int): int
        {
            var loc1=0;
            if (this._equipTargetType == EquipTargetType.PetEquipStrengthenTarget) 
            {
                loc1 = PetUtil.getEqStrengthAmount(arg1, this._mode);
            }
            else 
            {
                loc1 = PlayerEqStrengthInfo.getEqStrengthAmount(arg1, this._mode);
            }
            return loc1;
        }

        /* internal  */getToolTipData(arg1: int): ToolTipInfo
        {
            var loc7=null;
            var loc8=null;
            var loc11=0;
            var loc12=null;
            var loc13=null;
            var loc1=[];
            var loc2="";
            var loc3=this.getStrengthAmount(arg1);
            var loc4=this._curCareer;
            var loc5;
            if ((loc5 = StrengthAddConfig.instance.getStrengthenAddInfo(this._equipTargetType, loc4, arg1)) == null) 
            {
                return null;
            }
            var loc6=loc3 >= loc5.amount;
            if (arg1 <= 7) 
            {
                loc8 = ColorConfig.instance.getItemColorString(3);
            }
            else 
            {
                loc8 = ColorConfig.instance.getItemColorString(4);
            }
            loc2 = loc2 + HTMLUtil.addColor("<font size=\'14\'>" + Language.getStringByParam(30034, arg1, "<font color=\'#00ff00\'>", loc3, loc5.amount) + "</font></font>\n", loc8);
            if (loc6) 
            {
                loc2 = loc2 + HTMLUtil.addColor(Language.getString(30035) + "\n\n", "#00ff00");
                loc7 = "#f0ea3f";
            }
            else 
            {
                loc2 = loc2 + HTMLUtil.addColor(Language.getString(30036) + "\n\n", "#ff0000");
                loc7 = "#7c7c7c";
            }
            var loc9=this.getAttributeString(loc5);
            loc2 = loc2 + ("<textFormat leading=\'3\'>" + HTMLUtil.addColor(loc9, loc7) + "<textFormat>\n");
            loc1.push(loc2);
            if (arg1 < this._maxLevel) 
            {
                loc2 = "";
                if (loc6) 
                {
                    loc11 = this.getStrengthAmount(arg1 + 1);
                    loc12 = StrengthAddConfig.instance.getStrengthenAddInfo(this._equipTargetType, loc4, arg1 + 1);
                    loc13 = this.getAttributeString(loc12);
                    loc2 = loc2 + HTMLUtil.addColor(Language.getStringByParam(30037, arg1 + 1) + "(" + loc11 + "/" + loc12.amount + ")\n", "#7c7c7c");
                    loc2 = loc2 + ("<textFormat leading=\'3\'>" + HTMLUtil.addColor(loc13, "#7c7c7c") + "<textFormat>\n");
                    loc1.push(loc2);
                    loc2 = "";
                    loc2 = HTMLUtil.addColor(loc2 + Language.getStringByParam(30038, loc5.amount), "#7c7c7c");
                }
                else 
                {
                    loc2 = HTMLUtil.addColor(loc2 + Language.getStringByParam(30039, loc5.amount, arg1), "#7c7c7c");
                }
                loc1.push(loc2);
            }
            var loc10;
            return loc10 = new ToolTipInfo(NormalTooltip.ToolTipRenderType_Separate, loc1);
        }

        /* internal  */getAttributeString(arg1: StrengthenAddInfo): string
        {
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc1="";
            var loc5=StrengthAddConfig.instance.getAttributeInfo(arg1);
            var loc6=0;
            while (loc6 < loc5.length) 
            {
                loc2 = loc5[loc6];
                loc3 = loc2["name"] as string;
                loc4 = loc2["value"] as string;
                if (loc3.length != 2) 
                {
                    loc1 = loc1 + ("  " + loc3 + "    " + loc4 + "\n");
                }
                else 
                {
                    loc1 = loc1 + ("  " + loc3 + "            " + loc4 + "\n");
                }
                ++loc6;
            }
            return loc1;
        }

        /* internal  */onMouseOverHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.target as GButton;
            var loc2=int(loc1.name);
            loc1.toolTipData = this.getToolTipData(loc2);
            return;
        }

        /* internal  */updateEnable(arg1: Object=null): void
        {
            if (this._mode == GModuleEvent.Mode_Self) 
            {
                this.initEnable();
            }
            return;
        }

        public setOtherEquips(): void
        {
            this.initEnable();
            return;
        }

        public updateAddInfo(): void
        {
            this.initEnable();
            this.updateTooltipData();
            return;
        }

        /* internal */ /* var */_mode: string="自己";

        /* internal */ /* var */_equipTargetType: int;

        /* internal */ /* var */_curCareer: int;

        /* internal */ /* var */_btnDict: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_strengBtn: EqStrengthEnableBtn;

        /* internal */ /* var */_strengTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_lowLevel: int=5;

        /* internal */ /* var */_maxLevel: int=11;
    }
